//
//  CheckUtils.m
//  Tongcheng
//
//  Created by 邢广范 on 2017/4/9.
//  Copyright © 2017年 Tongcheng. All rights reserved.
//

#import "CheckUtils.h"

@implementation CheckUtils

+(NSString*)checkPhone:(NSString*)phone{
    if(phone.length==0){
        return @"请输入手机号";
    }else{
        NSString *regex = @"^(13[0-9]|17[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        BOOL isMatch = [pred evaluateWithObject:phone];
        if(!isMatch){
            return @"手机号格式不正确";
        }
        if(phone.length !=11){
            return @"手机号格式不正确";
        }
    }
    return nil;
}

+(NSString *)checkUserName:(NSString *)userName
{
    if (userName.length == 0) {
        return @"请输入用户名";
    }else if (userName.length > 60){
        return @"用户名格式不正确";
    }else{
        NSString *regex = @"[\u4e00-\u9fa5]+";
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        BOOL isMatch = [pred evaluateWithObject:userName];
        if (isMatch) {
            return @"用户名格式不正确";
        }
    }
    return nil;
}

@end
